﻿using MyWPF.Models;
using MyWPF.StaticData;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Newtonsoft.Json;

namespace MyWPF.ViewModel.Setting
{
    public class VM_SetWindow_Color : BaseViewModel
    {
        public VM_SetWindow_Color() 
        {
            _setColor01 = new DelegateCommand<object>(_SetColor01);
            _setColor02 = new DelegateCommand<object>(_SetColor02);
            _setColor03 = new DelegateCommand<object>(_SetColor03);
        }

        #region 事件绑定：切换主题颜色
        /// <summary>
        /// 切换主题颜色：01
        /// </summary>
        private ICommand _setColor01;
        public ICommand SetColor01
        {
            get { return _setColor01; }
            set
            {
                _setColor01 = value;
                OnPropertyChanged("SetColor01");
            }
        }

        private void OnPropertyChanged(string v)
        {
            throw new NotImplementedException();
        }

        private void _SetColor01(object obj)
        {
            StaticModels.staticInfo.config.NomalConfig.MainColor = new SolidColorBrush(Color.FromArgb(0xff, 0xea, 0x42, 0x35));
            StaticModels.staticInfo.config.NomalConfig.LightColor = new SolidColorBrush(Color.FromArgb(0xff, 0xfa, 0x52, 0x45));
            StaticModels.staticInfo.config.NomalConfig.FontColor = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0xff, 0xff));
            //将StaticModels.staticInfo.config序列化后保存
            string configStr = JsonConvert.SerializeObject(StaticModels.staticInfo.config);
            var filePath = "Assets/Json/Config.json";
            File.WriteAllText(filePath, configStr);

        }
        /// <summary>
        /// 切换主题颜色：02
        /// </summary>
        private ICommand _setColor02;
        public ICommand SetColor02
        {
            get { return _setColor02; }
            set
            {
                _setColor02 = value;
                OnPropertyChanged("SetColor02");
            }
        }
        private void _SetColor02(object obj)
        {
            StaticModels.staticInfo.config.NomalConfig.MainColor = new SolidColorBrush(Color.FromArgb(0xff, 0x07, 0xbf, 0x96));
            StaticModels.staticInfo.config.NomalConfig.LightColor = new SolidColorBrush(Color.FromArgb(0xff, 0x5e, 0xcc, 0xb4));
            StaticModels.staticInfo.config.NomalConfig.FontColor = new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0xff, 0xff));
            //将StaticModels.staticInfo.config序列化后保存
            string configStr = JsonConvert.SerializeObject(StaticModels.staticInfo.config);
            var filePath = "Assets/Json/Config.json";
            File.WriteAllText(filePath, configStr);
        }
        /// <summary>
        /// 切换主题颜色：03
        /// </summary>
        private ICommand _setColor03;
        public ICommand SetColor03
        {
            get { return _setColor03; }
            set
            {
                _setColor03 = value;
                OnPropertyChanged("SetColor03");
            }
        }
        private void _SetColor03(object obj)
        {
            StaticModels.staticInfo.config.NomalConfig.MainColor = new SolidColorBrush(Color.FromArgb(0xff, 0x5f, 0x63, 0x68));
            StaticModels.staticInfo.config.NomalConfig.LightColor = new SolidColorBrush(Color.FromArgb(0xff, 0xe9, 0xeb, 0xec));
            StaticModels.staticInfo.config.NomalConfig.FontColor = new SolidColorBrush(Color.FromArgb(0xff, 0x5f, 0x63, 0x68));
            //将StaticModels.staticInfo.config序列化后保存
            string configStr = JsonConvert.SerializeObject(StaticModels.staticInfo.config);
            var filePath = "Assets/Json/Config.json";
            File.WriteAllText(filePath, configStr);
        }
        #endregion
    }
}
